import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function2;
import java.util.Arrays;
import java.util.List;

public class HelloSpark {
    public static void main(String[] args) {
        SparkConf conf=new SparkConf().setMaster("local").setAppName("HelloSpark");
        JavaSparkContext javaSparkContext=new JavaSparkContext(conf);
        List<Integer> data=Arrays.asList(1,2,3,4,5,6,7);
        JavaRDD<Integer> distData=javaSparkContext.parallelize(data);
        Integer calcResult=distData.reduce(new Function2<Integer, Integer, Integer>() {
            @Override
            public Integer call(Integer integer, Integer integer2) throws Exception {
                return integer+integer2;
            }
        });
        //distData.reduce((a,b) -> a+b);
        /*List<Integer> result=distData.take(10);
        for (Integer i:result)
            System.out.println("result->>>>>>>>>>>>>>>>"+i);*/
        System.out.println("Final Result->>>>>>>>"+calcResult);
    }
}
